package view;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;

import controle.ControladorGUI;

import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.Locale;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class FramePrincipal extends JFrame {

	private DialogParticiparPartida participarPartida = null;
	private DialogCriarPartida criarPartida = null;
	private ControladorGUI ctrl;
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JButton jogoLocal_jb = null;
	private JButton internet_jb = null;
	private JButton criarJogoLan_jb = null;
	private JButton participarLan_jb = null;
	/**
	 * This is the default constructor
	 */
	public FramePrincipal(ControladorGUI ctrl) {
		super();
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent arg0) {
				sair();
			}
		});
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		ctrl.getSons().getAudioAbertura().loop();
		setLocale(new Locale("pt", "BR"));
		setResizable(false);
		setLocationRelativeTo(null);
		this.ctrl = ctrl;
		initialize();
		
	}
	
	private void sair(){
		ctrl.getSons().getAudioAbertura().stop();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {	
		this.setSize(367, 323);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(FramePrincipal.class.getResource("/imagens/logo2.jpg")));
		this.setContentPane(getJContentPane());
		this.setTitle("MONOPOLI");
		this.setLocationRelativeTo(null);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJogoLocal_jb(), null);
			jContentPane.add(getInternet_jb(), null);
			jContentPane.add(getCriarJogoLan_jb(), null);
			jContentPane.add(getParticiparLan_jb(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jogoLocal_jb	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJogoLocal_jb() {
		if (jogoLocal_jb == null) {
			jogoLocal_jb = new JButton();
			jogoLocal_jb.setText("Jogo Local");
			jogoLocal_jb.setEnabled(false);
			jogoLocal_jb.setBounds(new Rectangle(119, 49, 135, 22));
		}
		return jogoLocal_jb;
	}

	/**
	 * This method initializes internet_jb	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getInternet_jb() {
		if (internet_jb == null) {
			internet_jb = new JButton();
			internet_jb.setText("Internet");
			internet_jb.setEnabled(false);
			internet_jb.setBounds(new Rectangle(119, 98, 135, 26));
		}
		return internet_jb;
	}

	/**
	 * This method initializes criarJogoLan_jb	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCriarJogoLan_jb() {
		if (criarJogoLan_jb == null) {
			criarJogoLan_jb = new JButton();
			criarJogoLan_jb.setFont(new Font("Tahoma", Font.PLAIN, 14));
			criarJogoLan_jb.setToolTipText("Click aqui quando desejar criar uma partida na rede local.");
			criarJogoLan_jb.setText("Criar Jogo LAN");
			criarJogoLan_jb.setBounds(new Rectangle(119, 151, 135, 27));
			criarJogoLan_jb.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					criarPartida();
				}
			});
		}
		return criarJogoLan_jb;
	}
	
	private void criarPartida(){
		if(criarPartida == null)
			this.criarPartida = new DialogCriarPartida(this,this.ctrl);
		this.setVisible(false);
		this.criarPartida.setVisible(true);
	}

	/**
	 * This method initializes participarLan_jb	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getParticiparLan_jb() {
		if (participarLan_jb == null) {
			participarLan_jb = new JButton();
			participarLan_jb.setFont(new Font("Tahoma", Font.PLAIN, 14));
			participarLan_jb.setToolTipText("Click aqui para participar de uma partida numa rede local.");
			participarLan_jb.setText("Participar LAN");
			participarLan_jb.setBounds(new Rectangle(119, 205, 135, 28));
			participarLan_jb.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					participarLan();
				}
			});
		}
		return participarLan_jb;
	}
	
	private void participarLan(){
		if(participarPartida == null)
			participarPartida = new DialogParticiparPartida(this,ctrl);
		this.setVisible(false);
		this.participarPartida.setVisible(true);
	}

}  //  @jve:decl-index=0:visual-constraint="256,29"
